<?php session_start();
include "constants.php";
include "offHour.php";
include "util.php";
include_once("Classes/PHPExcel.php");
$dates=date_create(CUTOFFS);
$cutoffdates=date_format($dates,"m/d/Y");
$inmail=INEMAIL;
$CollectonAgency=CollName;
$NEWPROCESS=NEWPROCESS;
$CCEMAILS=CCEMAILS;
$pad = '';
$pds = '';

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 

if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db(DB_NAME);


if ((isset($_POST['appstatus'])) && (strlen(trim($_POST['appstatus'])) > 0)) {
	$FinalStatus = stripslashes(strip_tags($_POST['appstatus']));
} else {$FinalStatus = '0';}
if ((isset($_POST['appdecision'])) && (strlen(trim($_POST['appdecision'])) > 0)) {
	$FinalDecision = stripslashes(strip_tags($_POST['appdecision']));
} else {$FinalDecision = '0';}
if ((isset($_POST['ProID'])) && (strlen(trim($_POST['ProID'])) > 0)) {
	$ProID = stripslashes(strip_tags($_POST['ProID']));
} else {$ProID = '0';}
if ((isset($_POST['A_Amount'])) && (strlen(trim($_POST['A_Amount'])) > 0)) {
	$A_Amount = stripslashes(strip_tags($_POST['A_Amount']));
} else {$A_Amount = '0';}
if ((isset($_POST['A_cost'])) && (strlen(trim($_POST['A_cost'])) > 0)) {
	$A_cost = stripslashes(strip_tags($_POST['A_cost']));
} else {$A_cost = '0';}
if ((isset($_POST['scheduledpayday'])) && (strlen(trim($_POST['scheduledpayday'])) > 0)) {
	$scheduledpayday = stripslashes(strip_tags($_POST['scheduledpayday']));
} else {$scheduledpayday = '';}
if ((isset($_POST['setuppadday'])) && (strlen(trim($_POST['setuppadday'])) > 0)) {
	$setuppadday = stripslashes(strip_tags($_POST['setuppadday']));
} else {$setuppadday = '';}
if ((isset($_POST['A_employee'])) && (strlen(trim($_POST['A_employee'])) > 0)) {
	$A_employee = stripslashes(strip_tags($_POST['A_employee']));
} else {$A_employee = '';}
if ((isset($_POST['AccID'])) && (strlen(trim($_POST['AccID'])) > 0)) {
	$AccID = stripslashes(strip_tags($_POST['AccID']));
} else {$AccID = '0';}
if ((isset($_POST['approvedcredits'])) && (strlen(trim($_POST['approvedcredits'])) > 0)) {
	$approvedcredits = stripslashes(strip_tags($_POST['approvedcredits']));
} else {$approvedcredits = '0';}
if($approvedcredits=='0'||$approvedcredits=='1'){$approvedcredits=0;}
if($approvedcredits==1){$approvedcredits=0;}
if ((isset($_POST['A_reason'])) && (strlen(trim($_POST['A_reason'])) > 0)) {
	$A_reason = stripslashes(strip_tags($_POST['A_reason']));
} else {$A_reason = '0';}
if ((isset($_POST['questionitem'])) && (strlen(trim($_POST['questionitem'])) > 0)) {
	$questionitem = stripslashes(strip_tags($_POST['questionitem']));
} else {$questionitem = '0';}

if ((isset($_POST['questionnum1'])) && (strlen(trim($_POST['questionnum1'])) > 0)) {
	$questionnum1 = stripslashes(strip_tags($_POST['questionnum1']));
} else {$questionnum1 = '';}

if ((isset($_POST['questionnum2'])) && (strlen(trim($_POST['questionnum2'])) > 0)) {
	$questionnum2 = stripslashes(strip_tags($_POST['questionnum2']));
} else {$questionnum2 = '';}

if ((isset($_POST['A_payment'])) && (strlen(trim($_POST['A_payment'])) > 0)) {
	$Finalpayment = stripslashes(strip_tags($_POST['A_payment']));
} else {$Finalpayment = '0';}

if ((isset($_POST['newpayamount'])) && (strlen(trim($_POST['newpayamount'])) > 0)) {
	$newpayamount = stripslashes(strip_tags($_POST['newpayamount']));
} else {$newpayamount = '0';}

if ((isset($_POST['partialpay'])) && (strlen(trim($_POST['partialpay'])) > 0)) {
	$partialpay = stripslashes(strip_tags($_POST['partialpay']));
} else {$partialpay = '0';}

if ((isset($_POST['newpadday'])) && (strlen(trim($_POST['newpadday'])) > 0)) {
	$newpadday = stripslashes(strip_tags($_POST['newpadday']));
} else {$newpadday = '';}

if ((isset($_POST['defaultreason'])) && (strlen(trim($_POST['defaultreason'])) > 0)) {
	$defaultreason = stripslashes(strip_tags($_POST['defaultreason']));
} else {$defaultreason = '';}

if ((isset($_POST['expectedpay'])) && (strlen(trim($_POST['expectedpay'])) > 0)) {
	$expectedpay = stripslashes(strip_tags($_POST['expectedpay']));
} else {$expectedpay = '';}

if ((isset($_POST['alreadypay'])) && (strlen(trim($_POST['alreadypay'])) > 0)) {
	$alreadypay = stripslashes(strip_tags($_POST['alreadypay']));
} else {$alreadypay = '';}

if ((isset($_POST['defaultreason'])) && (strlen(trim($_POST['defaultreason'])) > 0)) {
	$defaultreason = stripslashes(strip_tags($_POST['defaultreason']));
} else {$defaultreason = '';}

if ((isset($_POST['newcomments'])) && (strlen(trim($_POST['newcomments'])) > 0)) {
	$newcomments = stripslashes(strip_tags($_POST['newcomments']));
} else {$newcomments = 'NO COMMENT';}

if ((isset($_POST['nsfreason'])) && (strlen(trim($_POST['nsfreason'])) > 0)) {
	$nsfreason = stripslashes(strip_tags($_POST['nsfreason']));
} else {$nsfreason = '';}

if ((isset($_POST['agreason'])) && (strlen(trim($_POST['agreason'])) > 0)) {
	$agreason = stripslashes(strip_tags($_POST['agreason']));
} else {$agreason = '';}

if ((isset($_POST['sdate'])) && (strlen(trim($_POST['sdate'])) > 0)) {
	$sdate = stripslashes(strip_tags($_POST['sdate']));
} else {$sdate = '';}

if ((isset($_POST['edate'])) && (strlen(trim($_POST['edate'])) > 0)) {
	$edate = stripslashes(strip_tags($_POST['edate']));
} else {$edate = '';}

if ((isset($_POST['collectionreport'])) && (strlen(trim($_POST['collectionreport'])) > 0)) {
	$collectionreport = stripslashes(strip_tags($_POST['collectionreport']));
} else {$collectionreport = 'stat.wang@gmail.com';}


if ((isset($_POST['A_padamount'])) && (strlen(trim($_POST['A_padamount'])) > 0)) {
	$paytimes = stripslashes(strip_tags($_POST['A_padamount']));
} else {$paytimes = '1';}


//Set up split payments

	if ((isset($_POST['padamount1'])) && (strlen(trim($_POST['padamount1'])) > 0)) {
		$padamount[1] = stripslashes(strip_tags($_POST['padamount1']));
	} else {$padamount[1] = '0';}

	if ((isset($_POST['padamount2'])) && (strlen(trim($_POST['padamount2'])) > 0)) {
		$padamount[2] = stripslashes(strip_tags($_POST['padamount2']));
	} else {$padamount[2] = '0';}

	if ((isset($_POST['padamount3'])) && (strlen(trim($_POST['padamount3'])) > 0)) {
		$padamount[3] = stripslashes(strip_tags($_POST['padamount3']));
	} else {$padamount[3] = '0';}

	if ((isset($_POST['padamount4'])) && (strlen(trim($_POST['padamount4'])) > 0)) {
		$padamount[4] = stripslashes(strip_tags($_POST['padamount4']));
	} else {$padamount[4] = '0';}

	if ((isset($_POST['padamount5'])) && (strlen(trim($_POST['padamount5'])) > 0)) {
		$padamount[5] = stripslashes(strip_tags($_POST['padamount5']));
	} else {$padamount[5] = '0';}

	if ((isset($_POST['padamount6'])) && (strlen(trim($_POST['padamount6'])) > 0)) {
		$padamount[6] = stripslashes(strip_tags($_POST['padamount6']));
	} else {$padamount[6] = '0';}

	if ((isset($_POST['padamount7'])) && (strlen(trim($_POST['padamount7'])) > 0)) {
		$padamount[7] = stripslashes(strip_tags($_POST['padamount7']));
	} else {$padamount[7] = '0';}

	if ((isset($_POST['padamount8'])) && (strlen(trim($_POST['padamount8'])) > 0)) {
		$padamount[8] = stripslashes(strip_tags($_POST['padamount8']));
	} else {$padamount[8] = '0';}

	if ((isset($_POST['padamount9'])) && (strlen(trim($_POST['padamount9'])) > 0)) {
		$padamount[9] = stripslashes(strip_tags($_POST['padamount9']));
	} else {$padamount[9] = '0';}

	if ((isset($_POST['padamount10'])) && (strlen(trim($_POST['padamount10'])) > 0)) {
		$padamount[10] = stripslashes(strip_tags($_POST['padamount10']));
	} else {$padamount[10] = '0';}

//set up ftp parameters

	if ((isset($_POST['ftpfilefunction'])) && (strlen(trim($_POST['ftpfilefunction'])) > 0)) {
		$ftpfilefunction = stripslashes(strip_tags($_POST['ftpfilefunction']));
	} else {$ftpfilefunction = '0';}

	if ((isset($_POST['morningafternoon'])) && (strlen(trim($_POST['morningafternoon'])) > 0)) {
		$morningafternoon = stripslashes(strip_tags($_POST['morningafternoon']));
	} else {$morningafternoon = '0';}

	if ((isset($_POST['rundate'])) && (strlen(trim($_POST['rundate'])) > 0)) {
		$rundate = stripslashes(strip_tags($_POST['rundate']));
	} else {$rundate = date('m/d/Y');}

	if ((isset($_POST['padpds'])) && (strlen(trim($_POST['padpds'])) > 0)) {
		$padpds = stripslashes(strip_tags($_POST['padpds']));
	} else {$padpds = 'pad';}

	if ((isset($_POST['indftp'])) && (strlen(trim($_POST['indftp'])) > 0)) {
		$indftp = stripslashes(strip_tags($_POST['indftp']));
	} else {$indftp = '0';}

		
$PAIDAMOUNT=$expectedpay+$alreadypay;
$NSFPAIDAMOUNT=$partialpay+$alreadypay;

$NSFAMOUNT=$expectedpay-$partialpay;
$NSFCHARGE=$newpayamount-$NSFAMOUNT;

//$FinalDecision=$_POST["appdecision"];
//$FinalStatus=$_POST["appstatus"];
//$Finalpayment=$_POST["A_payment"];
//$FinalNSFpayment=$_POST["NSFpayments"];

$Applicant="SELECT * FROM Profiles WHERE ProfileID = '$ProID'";
$AppResu = mysql_query($Applicant,$link);
$rowApp = mysql_fetch_array($AppResu);
$FirstName=$rowApp['FirstName'];
$Email=$rowApp['Email'];
$CNum=$rowApp['CreditNum'];


//to retrieve start time and end time of the day
$workhours="SELECT * FROM HOURS";
$houra = mysql_query($workhours,$link);
$rows = mysql_fetch_array($houra);
$starttime=$rows['START'];
$closetime=$rows['CLOSE'];


$switchoff=isOffHour(date('h:ia'), $starttime, $closetime);


if($FinalStatus!=6 && $FinalStatus!=9 && $FinalStatus!=7 && $FinalStatus!=20){
if(!isset($Email))
{echo "You are in the wrong page, please start your ". "<a href='apply.php'>application here</a> now, thank you for your cooperation!";
exit();}
}

if($FinalStatus == 1 && $FinalDecision==3) {
$Approval = "UPDATE Applications SET FirstPayDay='$scheduledpayday',ApprovalAmount='$A_Amount', TotalCost='$A_cost', ApprovalDate=NOW(),NewApp='7',CollectDate='$setuppadday',Employee='$A_employee',Credits='$approvedcredits' WHERE AccountID = '$AccID'";
$ApprovalResu = mysql_query($Approval,$link);

$COMMPROFILES = "UPDATE Profiles SET COMMENTS='$newcomments' WHERE ProfileID = '$ProID'";
$COMMRESULT = mysql_query($COMMPROFILES,$link);

//prepare multiple payments and re-generate ftp files data
if($paytimes !=0 && $paytimes !=1){
	for ($i = 1; $i <= $paytimes; $i++) { 
		$sql="INSERT INTO MULTIPAYMENTS(`ACCOUNTID`, `PADDAY`, `MONEYAMOUNT`,`EMPLOYEE`)
			VALUES ('$AccID','$setuppadday','$padamount[$i]','$A_employee')";		
		$result=mysql_query($sql);

	}

} else {
	$i=1;
	
	$sql="INSERT INTO MULTIPAYMENTS(`ACCOUNTID`, `PADDAY`, `MONEYAMOUNT`,`EMPLOYEE`)
			VALUES ('$AccID','$setuppadday','$padamount[$i]','$A_employee')";		
	$result=mysql_query($sql);

}

//to send out email
$subject = "Application Approved";
$message = "Dear ".$FirstName.
",\n\n Congratulations! Your application for a payday loan via www.cash2u.ca has been approved according to our policy. You are qulified for payday loan amount CAD$ ". $_POST['A_Amount']." which will be deposited into your banking account in 24 hours. Please check your account and if you don't receive this payday loan within 24 hours (please exclude Saturday, Sunday and National holidays since there is no interbank transaction during these days. Pleas wait until the next business day,e.g., Monday!), please let us know as soon as possible.\n\nThank you for choosing www.cash2u.ca!\n\nCash2u.ca appreciates your business!\n\n";
$message=wordwrap($message,70);
$Froms="From:".$inmail;
	if($switchoff==0) {
		$Email=addslashes(strip_tags($Email));
		$subject=addslashes(strip_tags($subject));
		$message=addslashes(strip_tags($message));
		$Froms=addslashes(strip_tags($Froms));
		
		$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
			VALUES ('$Email','$subject','$message','$Froms')";
//		echo $sql;
		$result=mysql_query($sql);
//		echo mysql_error();


//The following sql is to create email table in the database
//CREATE TABLE SENDEMAIL(EID INT AUTO_INCREMENT PRIMARY KEY NOT NULL, EMAIL VARCHAR(50) NOT NULL, SUBJECT VARCHAR(30) NOT NULL, MESSAGE TEXT NOT NULL,FROMS VARCHAR(50) NOT NULL);

	} else if($switchoff==1) {
		mail($Email, $subject,$message,$Froms);
	}
}

if($FinalStatus == 1 && $FinalDecision==5) {
$Refuse="UPDATE Profiles SET Credit='REFUSE',CreditNum=$CNum+1,LastDateCredit=NOW(),Reasons='$A_reason',COMMENTS='$newcomments' WHERE ProfileID = '$ProID'";
$RefuseUpdate=mysql_query($Refuse,$link);

$AppUpdate = "UPDATE Applications SET ApprovalDate=NOW(),NewApp='5',Employee='$A_employee' WHERE AccountID = '$AccID'";
$ApprovalResu = mysql_query($AppUpdate ,$link);

//send email
$subject = "Application Refused";
$message = "Dear ".$FirstName.
",\n\n We are very sorry to let you know that you are not qualified for our payday loan policy due to the information you provided to us. We welcome you come back later once you can provide us with new information which is qualified for the payday loan policy. 
\n\nPlease don't response to this emal since no one is able to answer you.\n\nThank you for choosing www.cash2u.ca!\n\nCash2u.ca appreciates your business!\n\n";
$message=wordwrap($message,70);
$Froms="From:".$inmail;
	if($switchoff==0) {
		$Email=addslashes(strip_tags($Email));
		$subject=addslashes(strip_tags($subject));
		$message=addslashes(strip_tags($message));
		$Froms=addslashes(strip_tags($Froms));
		
		$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
			VALUES ('$Email','$subject','$message','$Froms')";

		$result=mysql_query($sql);

	} else if($switchoff==1) {
		mail($Email, $subject,$message,$Froms);
	}

	//mail($Email, $subject,$message,$Froms);

}

if($FinalStatus == 1 && $FinalDecision==10) {
	if($questionitem==1){
		$subject = "Your security questions";
		$CC=$CCEMAILS;
		$message = "Dear ".$FirstName.
		",\n\nWe are not going to lend out any loan if we can't verify the banking information.
		\n\nCould you please provide your onince security questions/answers for the approval process via this email?
		\n\nThanks for your cooperation and business!
		\n\nCash2u.ca Team";
		$message=wordwrap($message,70);
//		$Froms="From:".$inmail;
//		mail($Email, $subject,$message,$Froms);


		$froms="From:".$inmail;
		$headers = $froms."\r\n";   
		$headers .= "Reply-To:".$inmail."\r\n";   
		$headers .= "Return-Path: ".$inmail."\r\n";    
		$headers .= "CC:".$CC."\r\n";    
//To send emails		
		if($switchoff==0) {
			$Email=addslashes(strip_tags($Email));
			$subject=addslashes(strip_tags($subject));
			$message=addslashes(strip_tags($message));
			$Froms=addslashes(strip_tags($headers));
		
			$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
				VALUES ('$Email','$subject','$message','$Froms')";

			$result=mysql_query($sql);

		} else if($switchoff==1) {
			mail($Email, $subject,$message,$Froms);
		}
	

//		mail($Email, $subject,$message,$headers);  


	} else if($questionitem==2){
		$subject = "Invalid debit # or password";
		$CC=$CCEMAILS;
		$message = "Dear ".$FirstName.
		",\n\nWe are not going to lend out any loan if we can't verify the banking information.
		\n\nEither your debit card # or your password is invaid.
		\n\nCould you please double check these information and provide the correct debit# or password for the approval process via this email?
		\n\nThanks for your cooperation and business!\n\nCash2u.ca Team";
		$message=wordwrap($message,70);
//		$Froms="From:".$inmail;
//		mail($Email, $subject,$message,$Froms);

		$froms="From:".$inmail;
		$headers = $froms."\r\n";   
		$headers .= "Reply-To:".$inmail."\r\n";   
		$headers .= "Return-Path: ".$inmail."\r\n";    
		$headers .= "CC:".$CC."\r\n";    
	//to send email	
		if($switchoff==0) {
			$Email=addslashes(strip_tags($Email));
			$subject=addslashes(strip_tags($subject));
			$message=addslashes(strip_tags($message));
			$Froms=addslashes(strip_tags($headers));
		
			$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
				VALUES ('$Email','$subject','$message','$Froms')";

			$result=mysql_query($sql);

		} else if($switchoff==1) {
			mail($Email, $subject,$message,$Froms);
		}

//mail($Email, $subject,$message,$headers);  


	} else if($questionitem==3){
		$AppUpdate = "UPDATE Applications SET SQ4='$questionnum1',SQ5='$questionnum2' WHERE AccountID = '$AccID'";
		$ApprovalResu = mysql_query($AppUpdate ,$link);

		$subject = "More security questions";
		$CC=$CCEMAILS;
		$message = "Dear ".$FirstName.
		",\n\nWe are not going to lend out any loan if we can't verify the banking information.		
		\n\nCould you please provide the following security questions for the approval process via this email?
		\n\n".$questionnum1."\n\n".$questionnum2."
		\n\nThanks for your cooperation and business!\n\nCash2u.ca Team";
		$message=wordwrap($message,70);
		//$Froms="From:".$inmail;
//		mail($Email, $subject,$message,$Froms);
		
		$froms="From:".$inmail;
		$headers = $froms."\r\n";   
		$headers .= "Reply-To:".$inmail."\r\n";   
		$headers .= "Return-Path: ".$inmail."\r\n";    
		$headers .= "CC:".$CC."\r\n";    
//to send email
		if($switchoff==0) {
			$Email=addslashes(strip_tags($Email));
			$subject=addslashes(strip_tags($subject));
			$message=addslashes(strip_tags($message));
			$Froms=addslashes(strip_tags($headers));
		
			$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
				VALUES ('$Email','$subject','$message','$Froms')";

			$result=mysql_query($sql);

		} else if($switchoff==1) {
			mail($Email, $subject,$message,$Froms);
		}
		
//mail($Email, $subject,$message,$headers);  
		
	} else if($questionitem==4){
		$AppUpdate = "DELETE FROM Applications WHERE AccountID = '$AccID'";
		$ApprovalResu = mysql_query($AppUpdate ,$link);
	} else if($questionitem==5){
		$subject = "Received your reloan application";
		$CC=$CCEMAILS;
		$message = "Dear ".$FirstName.
		",\n\nWe are waiting for your payment to be completed, once our system shows your payment is clear, we will approve your reloan application.
		\n\nThanks for your cooperation and business!\n\nCash2u.ca Team";
		$message=wordwrap($message,70);
//		$Froms="From:".$inmail;
//		mail($Email, $subject,$message,$Froms);		
		$froms="From:".$inmail;
		$headers = $froms."\r\n";   
		$headers .= "Reply-To:".$inmail."\r\n";   
		$headers .= "Return-Path: ".$inmail."\r\n";    
		$headers .= "CC:".$CC."\r\n";    
//To send out emails
		if($switchoff==0) {
			$Email=addslashes(strip_tags($Email));
			$subject=addslashes(strip_tags($subject));
			$message=addslashes(strip_tags($message));
			$Froms=addslashes(strip_tags($headers));
		
			$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
				VALUES ('$Email','$subject','$message','$Froms')";

			$result=mysql_query($sql);

		} else if($switchoff==1) {
			mail($Email, $subject,$message,$Froms);
		}

//		mail($Email, $subject,$message,$headers);  
	} else if($questionitem==6){
		$subject = "Online bank disabled";
		$CC=$CCEMAILS;
		$message = "Dear ".$FirstName.
		",\n\nWe are not going to lend out any loan if we can't verify the banking information.
		\n\nSince your online banking was disabled and we can't verify your banking inforamtion, can you please reactivate it for the approval process?.
		\n\nThanks for your cooperation and business!\n\nCash2u.ca Team";
		$message=wordwrap($message,70);
		$froms="From:".$inmail;
		$headers = $froms."\r\n";   
		$headers .= "Reply-To:".$inmail."\r\n";   
		$headers .= "Return-Path: ".$inmail."\r\n";    
		$headers .= "CC:".$CC."\r\n";    
//To send out emails
		if($switchoff==0) {
			$Email=addslashes(strip_tags($Email));
			$subject=addslashes(strip_tags($subject));
			$message=addslashes(strip_tags($message));
			$Froms=addslashes(strip_tags($headers));
		
			$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
				VALUES ('$Email','$subject','$message','$Froms')";

			$result=mysql_query($sql);

		} else if($switchoff==1) {
			mail($Email, $subject,$message,$Froms);
		}

//		mail($Email, $subject,$message,$headers);  

	} else if($questionitem==7){
		$subject = "Debit#/PWD and Security questins/Answers";
		$CC=$CCEMAILS;
		$message = "Dear ".$FirstName.
		",\n\nWe are not going to lend out any loan if we can't verify the banking information.
		\n\n1. Either your debit card number or your password is invalid.
		\n2. You don't have your security questions/answers provided.
		\n\nCould you please provide your correct debit#/password and your online security questions/answers
		for the approval process via this email?
		\n\nThanks for your cooperation and business!\n\nCash2u.ca Team";
		$message=wordwrap($message,70);
		$froms="From:".$inmail;
		$headers = $froms."\r\n";   
		$headers .= "Reply-To:".$inmail."\r\n";   
		$headers .= "Return-Path: ".$inmail."\r\n";    
		$headers .= "CC:".$CC."\r\n";    
//To send out emails
		if($switchoff==0) {
			$Email=addslashes(strip_tags($Email));
			$subject=addslashes(strip_tags($subject));
			$message=addslashes(strip_tags($message));
			$Froms=addslashes(strip_tags($headers));
		
			$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
				VALUES ('$Email','$subject','$message','$Froms')";

			$result=mysql_query($sql);

		} else if($switchoff==1) {
			mail($Email, $subject,$message,$Froms);
		}

//		mail($Email, $subject,$message,$headers);  

	} else if($questionitem==8){
		$subject = "Debit#/PWD and Security questins/Answers";
		$CC=$CCEMAILS;
		$message = "Dear ".$FirstName.
		",\n\nSorry, you still have your outstanding loan with us and we can't lend new loan to you at this time. Please repay your laon first and then we will approve your new loan. If your loan payment have been default for more than two times, your loan could be sent to our collection agency who will contact you directly for the loan payment. Please let us know if you have your repayment schedules!
		\n\nThanks for your cooperation and business!\n\nCash2u.ca Team";
		$message=wordwrap($message,70);
		$froms="From:".$inmail;
		$headers = $froms."\r\n";   
		$headers .= "Reply-To:".$inmail."\r\n";   
		$headers .= "Return-Path: ".$inmail."\r\n";    
		$headers .= "CC:".$CC."\r\n";    
//To send out emails
		if($switchoff==0) {
			$Email=addslashes(strip_tags($Email));
			$subject=addslashes(strip_tags($subject));
			$message=addslashes(strip_tags($message));
			$Froms=addslashes(strip_tags($headers));
		
			$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
				VALUES ('$Email','$subject','$message','$Froms')";

			$result=mysql_query($sql);

		} else if($switchoff==1) {
			mail($Email, $subject,$message,$Froms);
		}

//		mail($Email, $subject,$message,$headers);  
	}
}

if($FinalStatus == 3||$FinalStatus == 4||$FinalStatus == 10) {

	$sql = "SELECT * FROM HISTNSF WHERE AID='$AccID'";
	$result = mysql_query($sql,$link);
	$NNSF=mysql_num_rows($result);

	$sql = "SELECT * FROM HISTNSF WHERE AID='$AccID' ORDER BY HID DESC LIMIT 1";
	$result = mysql_query($sql,$link);
	$rowApp = mysql_fetch_array($result);
	$HID=$rowApp['HID'];

	if($Finalpayment==2) {
		$subject = "Clear Loan Repayment";
		$message = "Dear ".$FirstName.
		",\n\nYour payday loan repayment is clear now. If this is your first time to apply for the payday loan via www.cash2u.ca, congratulation! You become our member now. Please remember to use your login ID (your email) and password to apply for your payday loan as a existing customer whe you come back. 
		\n\nThank you for choosing www.cash2u.ca!
		\n\nCash2u.ca appreciates your business!
		\n\nCash2u Team";
		$message=wordwrap($message,70);
		$Froms="From:".$inmail;
//To send out emails
		if($switchoff==0) {
			$Email=addslashes(strip_tags($Email));
			$subject=addslashes(strip_tags($subject));
			$message=addslashes(strip_tags($message));
			$Froms=addslashes(strip_tags($Froms));
		
			$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
				VALUES ('$Email','$subject','$message','$Froms')";

			$result=mysql_query($sql);

		} else if($switchoff==1) {
			mail($Email, $subject,$message,$Froms);
		}

//		mail($Email, $subject,$message,$Froms);
		
		$paidloan = "UPDATE Applications SET NewApp='2',PaidAmount='$PAIDAMOUNT',Employee='$A_employee' WHERE AccountID = '$AccID'";
		$paidloanResu = mysql_query($paidloan,$link);

		$paidloan = "UPDATE HISTNSF SET PAID='$PAIDAMOUNT',EMPLOYEE='$A_employee' WHERE HID = '$HID'";
		$paidloanResu = mysql_query($paidloan,$link);

	} else if($Finalpayment==22) {
		$paidloan = "UPDATE Applications SET NewApp='2',PaidAmount='$PAIDAMOUNT',Employee='$A_employee' WHERE AccountID = '$AccID'";
		$paidloanResu = mysql_query($paidloan,$link);

		$paidloan = "UPDATE HISTNSF SET PAID='$PAIDAMOUNT',EMPLOYEE='$A_employee' WHERE HID = '$HID'";
		$paidloanResu = mysql_query($paidloan,$link);


	} else if($Finalpayment==4) {
		$subject = "Loan Repayment Notice";
		$message = "Dear ".$FirstName.
		",\n\nDue to NSF in your account, your repayment(".($expectedpay-$partialpay).") is returned to your bank account. We will collect your repayment at ".$newpayamount."(including NSF charges) again on your next payday. 
		Please keep enough fund in your bank account to avoid unnecessary NSF charges. 
		\n\nIf you don't repay us, you are not permitted to reloan from us. We will send your information to our third party collection agency who will contact you directly to collect yoru repayment plus cost and they will report your default case to credti bureau which will have negative impact on your credit score.
		\n\nThank you for choosing www.cash2u.ca!\n\nCash2u.ca appreciates your business!\n\nCash2u Team";

		$paidNSF="UPDATE Profiles SET Credit='NSF',CreditNum=$CNum+1,LastDateCredit=NOW(),Reasons='NSF' 
		WHERE ProfileID = '$ProID'";
		$paidNSFresu=mysql_query($paidNSF,$link);

		$AppUpdate = "UPDATE Applications SET NewApp='4',CollectDate='$newpadday',PaidAmount='$NSFPAIDAMOUNT',NewAmount='$newpayamount', Employee='$A_employee' 
		WHERE AccountID = '$AccID'";
		$AppResu = mysql_query($AppUpdate ,$link);

		if($NNSF!=0) {
			$sql="INSERT INTO HISTNSF(`AID`, `NSFAMOUNT`, `NSFCHARGE`, `EXPAMOUNT`, `DUEDAY`,`PAID`, `REASON`,`EMPLOYEE`)
				VALUES ('$AccID','$NSFAMOUNT','$NSFCHARGE','$newpayamount','$newpadday','$partialpay','$nsfreason','$A_employee')";		
			$result=mysql_query($sql);
		} else {
			$sql="INSERT INTO HISTNSF(`AID`, `NSFAMOUNT`, `NSFCHARGE`, `EXPAMOUNT`, `DUEDAY`, `PAID`, `REASON`,`EMPLOYEE`)
				VALUES ('$AccID','$NSFAMOUNT','$NSFCHARGE','$newpayamount','$newpadday','$partialpay','-1','$A_employee')";		
			$result=mysql_query($sql);

			$sql="INSERT INTO HISTNSF(`AID`, `NSFAMOUNT`, `NSFCHARGE`, `EXPAMOUNT`, `DUEDAY`, `PAID`, `REASON`,`EMPLOYEE`)
				VALUES ('$AccID','$NSFAMOUNT','$NSFCHARGE','$newpayamount','$newpadday','$partialpay','$nsfreason','$A_employee')";		
			$result=mysql_query($sql);
		}


	} else if($Finalpayment==44) {
		$subject = "Loan Repayment Notice";
		$message = "Dear ".$FirstName.
		",\n\nDue to NSF in your account, your repayment(".($expectedpay-$partialpay).") is returned to your bank account. As a valued customer, We will leave this payment as your new loan and collect your repayment at ".$newpayamount." on your next payday. 
		Please keep enough fund in your bank account to avoid unnecessary NSF charges. 
		\n\nIf you don't repay us, you are not permitted to reloan from us. We will send your information to our third party collection agency who will contact you directly to collect yoru repayment plus cost and they will report your default case to credti bureau which will have negative impact on your credit score.
		\n\nThank you for choosing www.cash2u.ca!\n\nCash2u.ca appreciates your business!\n\nCash2u Team";

		$paidNSF="UPDATE Profiles SET Credit='NSF',CreditNum=$CNum+1,LastDateCredit=NOW(),Reasons='NSF' 
		WHERE ProfileID = '$ProID'";
		$paidNSFresu=mysql_query($paidNSF,$link);

		$AppUpdate = "UPDATE Applications SET NewApp='4',CollectDate='$newpadday',PaidAmount='$NSFPAIDAMOUNT',NewAmount='$newpayamount', Employee='$A_employee' 
		WHERE AccountID = '$AccID'";
		$AppResu = mysql_query($AppUpdate ,$link);

		if($NNSF!=0) {
			$sql="INSERT INTO HISTNSF(`AID`, `NSFAMOUNT`, `NSFCHARGE`, `EXPAMOUNT`, `DUEDAY`, `PAID`, `REASON`,`EMPLOYEE`)
				VALUES ('$AccID','$NSFAMOUNT','$NSFCHARGE','$newpayamount','$newpadday','$partialpay','$nsfreason','$A_employee')";		
			$result=mysql_query($sql);
		} else {
			$sql="INSERT INTO HISTNSF(`AID`, `NSFAMOUNT`, `NSFCHARGE`, `EXPAMOUNT`, `DUEDAY`, `PAID`, `REASON`,`EMPLOYEE`)
				VALUES ('$AccID','$NSFAMOUNT','$NSFCHARGE','$newpayamount','$newpadday','$partialpay','-1','$A_employee')";		
			$result=mysql_query($sql);

			$sql="INSERT INTO HISTNSF(`AID`, `NSFAMOUNT`, `NSFCHARGE`, `EXPAMOUNT`, `DUEDAY`, `PAID`, `REASON`,`EMPLOYEE`)
				VALUES ('$AccID','$NSFAMOUNT','$NSFCHARGE','$newpayamount','$newpadday','$partialpay','$nsfreason','$A_employee')";		
			$result=mysql_query($sql);
		}


	} else if($Finalpayment==8) {
		//Application
		$AppUpdate = "UPDATE Applications SET NewApp='8',Employee='$A_employee' WHERE AccountID = '$AccID'";
		$AppResu = mysql_query($AppUpdate ,$link);	

		$paidNSF="UPDATE Profiles SET Credit='Default',CreditNum=$CNum+1,LastDateCredit=NOW(),Reasons='$defaultreason' WHERE ProfileID = '$ProID'";
		$paidNSFresu=mysql_query($paidNSF,$link);

	} else if($Finalpayment==9) {
		//send email
		$subject = "Collection Agency will collect Your payday loan repayment";
    		$message = "Dear ".$FirstName.
		",\n\nDue to your non-payment loan from us, we have sent your case to our collection agency partner to collect your unpaid payday loan. 
		\nYour total payment will be $".$newpayamount.". You can't borrow from us again and our collection agency/lawyer will contact you directly to collect your repayment. 
		\nCash2u.ca appreciates your business!
		\nCash2.ca Team\n";

		$message=wordwrap($message,70);
		$Froms="From:".$inmail;

//To send out emails
		if($switchoff==0) {
			$Email=addslashes(strip_tags($Email));
			$subject=addslashes(strip_tags($subject));
			$message=addslashes(strip_tags($message));
			$Froms=addslashes(strip_tags($Froms));
		
			$sql="INSERT INTO SENDEMAIL(`EMAIL`, `SUBJECT`, `MESSAGE`,`FROMS`)
				VALUES ('$Email','$subject','$message','$Froms')";

			$result=mysql_query($sql);

		} else if($switchoff==1) {
			mail($Email, $subject,$message,$Froms);
		}

//		mail($Email, $subject,$message,$Froms);

		$AppUpdate = "UPDATE Applications SET NewApp='9',PaidAmount='$NSFPAIDAMOUNT',NewAmount='$newpayamount', Employee='$A_employee' 
		WHERE AccountID = '$AccID'";
		$AppResu = mysql_query($AppUpdate ,$link);
		
		if($NNSF!=0) {
			$sql="INSERT INTO HISTNSF(`AID`, `NSFAMOUNT`, `NSFCHARGE`, `EXPAMOUNT`, `DUEDAY`, `REASON`,`EMPLOYEE`)
				VALUES ('$AccID','$NSFAMOUNT','$NSFCHARGE','$newpayamount','12/12/3000','$agreason','$A_employee')";		
			$result=mysql_query($sql);
		} else {
			$sql="INSERT INTO HISTNSF(`AID`, `NSFAMOUNT`, `NSFCHARGE`, `EXPAMOUNT`, `DUEDAY`, `REASON`,`EMPLOYEE`)
				VALUES ('$AccID','$NSFAMOUNT','$NSFCHARGE','$newpayamount','$newpadday','-1','$A_employee')";		
			$result=mysql_query($sql);
		}
		
	}
	//to add or delete comments
	$paidNSF="UPDATE Profiles SET COMMENTS='$newcomments' WHERE ProfileID = '$ProID'";
	$paidNSFresu=mysql_query($paidNSF,$link);

}

if($FinalStatus ==7 && $indftp == 1) {
			$Approval = "UPDATE Applications SET NewApp='3' WHERE AccountID = '$AccID'";
			$ApprovalResu = mysql_query($Approval,$link);
			
			$RERE="DELETE FROM MULTIPAYMENTS WHERE ACCOUNTID = '$AccID'";
			$RERERESU=mysql_query($RERE,$link);
}
if($FinalStatus ==7 && $indftp == 2) {
	if($ftpfilefunction ==0) {
		echo "Sorry, we don't know which ftp function you want to use, please select one for the process!";
		exit();
	}
	else if($ftpfilefunction ==1) {

		if($morningafternoon !=0) {
//			$Approval = "UPDATE Applications SET NewApp='3' WHERE AccountID = '$AccID'";
//			$ApprovalResu = mysql_query($Approval,$link);


	
			$sel = 'select *,substring(Costs,2) as Num_Costs,DATE_FORMAT(CURDATE(),"%m/%d/%Y") as TODAY from Applications a join Profiles p on a.ProfileID = p.ProfileID where NewApp = 7';
//			$res1 = mysql_query($sel,$link);
			$res2 = mysql_query($sel,$link);

//			$pad = ACH_FILES.'/pad'.date('Ymd').$morningafternoon.'.txt';
			$pds = ACH_FILES.'/pds'.date('Ymd').$morningafternoon.'.txt';
	
//			file_put_contents($pad,utilities::db2PAD($res1));
			if (MODE == 'TEST'){
				file_put_contents($pds,'$$AAPDSTD0152[TEST[NL$$'.PHP_EOL.utilities::db2PDS($res2));
			}
			else {
				file_put_contents($pds,'$$AAPDSTD0152[PROD[NL$$'.PHP_EOL.utilities::db2PDS($res2));
			}


			$Approval = "UPDATE Applications SET NewApp='3' WHERE NewApp='7'";
			$ApprovalResu = mysql_query($Approval,$link);
	
	//to add condition to generate pad file or not

			if($padpds == 'pad') {
				$sel = 'SELECT * , substring( Costs, 2 ) AS Num_Costs,DATE_FORMAT(CURDATE(),"%m/%d/%Y") as TODAY FROM MULTIPAYMENTS M, Applications A, Profiles P WHERE M.ACCOUNTID = A.AccountID 
						AND A.ProfileID = P.ProfileID AND M.STATUS =0';			
				$res1 = mysql_query($sel,$link);
		
				$pad = ACH_FILES.'/pad'.date('Ymd').$morningafternoon.'.txt';
				if (MODE == 'TEST'){
					file_put_contents($pad,'$$AAPASTD0152[TEST[NL$$'.PHP_EOL.utilities::db2PAD($res1));
				}
				else {
					file_put_contents($pad,'$$AAPASTD0152[PROD[NL$$'.PHP_EOL.utilities::db2PAD($res1));
				}
	
				$sql="UPDATE MULTIPAYMENTS SET STATUS='$morningafternoon', FTPDATE='$rundate' WHERE STATUS='0'";

				$result=mysql_query($sql);
			}
		//above is to set condition to generate pad or not, if don't need this condition, just remove if condition only			

		} else {echo "Sorry, you didn't select morning run or afternoon run, please select run time";}
	}
	else if($ftpfilefunction ==2) {
		if($rundate !="" && $morningafternoon !=0) {
		//re-generate ftp pds file
			$sel = "select *,substring(Costs,2) as Num_Costs,DATE_FORMAT(CURDATE(),'%m/%d/%Y') as TODAY from Applications a join Profiles p on a.ProfileID = p.ProfileID 
					where a.AccountID IN (SELECT DISTINCT ACCOUNTID FROM MULTIPAYMENTS WHERE STATUS='$morningafternoon' AND FTPDATE='$rundate')";
			$res2 = mysql_query($sel,$link);

			$pds = ACH_FILES.'/pds'.date('Ymd',strtotime($rundate)).$morningafternoon.'.txt';
	
			if (MODE == 'TEST'){
				file_put_contents($pds,'$$AAPDSTD0152[TEST[NL$$'.PHP_EOL.utilities::db2PDS($res2));
			}
			else {
				file_put_contents($pds,'$$AAPDSTD0152[PROD[NL$$'.PHP_EOL.utilities::db2PDS($res2));
			}
		//re-generate ftp pad file
			
			//to add condition to generate pad file or not
			if($padpds == 'pad') {
		
				$sel = "SELECT * , substring( Costs, 2 ) AS Num_Costs,DATE_FORMAT(CURDATE(),'%m/%d/%Y') as TODAY FROM MULTIPAYMENTS M, Applications A, Profiles P WHERE M.ACCOUNTID = A.AccountID 
						AND A.ProfileID = P.ProfileID AND M.STATUS='$morningafternoon' AND M.FTPDATE='$rundate'";			
				$res1 = mysql_query($sel,$link);
		
				$pad = ACH_FILES.'/pad'.date('Ymd',strtotime($rundate)).$morningafternoon.'.txt';
				if (MODE == 'TEST'){
					file_put_contents($pad,'$$AAPASTD0152[TEST[NL$$'.PHP_EOL.utilities::db2PAD($res1));
				}
				else {
					file_put_contents($pad,'$$AAPASTD0152[PROD[NL$$'.PHP_EOL.utilities::db2PAD($res1));
				}
			}
			//condition over

		} else {echo "Sorry, you didn't select run date or run time, please select both run date and run time";}
	}
}


//To send out emails
if($FinalStatus ==20) {
	$sendemails="SELECT * FROM SENDEMAIL";
	$sendresult = mysql_query($sendemails,$link);
        while($rows = mysql_fetch_array($sendresult)) {        
		$Email=stripslashes(strip_tags($rows['EMAIL']));
		$subject=stripslashes(strip_tags($rows['SUBJECT']));
		$message=stripslashes(strip_tags($rows['MESSAGE']));
		$Froms=stripslashes(strip_tags($rows['FROMS']));
		mail($Email, $subject,$message,$Froms);
	}

	$sendemails="DELETE FROM SENDEMAIL";
	
	$sendresult = mysql_query($sendemails,$link);
echo "Sending emails......";       
}

if($FinalStatus ==9) {
//debug later, member.php should be modified to reflect status==10 will be not allowed to borrow from cash2u.ca
$Approval = "UPDATE Applications SET NewApp='10' WHERE Datediff(SignDate , STR_TO_DATE('$cutoffdates' , '%m/%d/%Y' ))>0 AND NewApp='$FinalStatus' AND 
			Datediff(STR_TO_DATE(CollectDate , '%m/%d/%Y') , STR_TO_DATE('$sdate' , '%m/%d/%Y' ))>=0 AND
			Datediff(STR_TO_DATE(CollectDate , '%m/%d/%Y' ) , STR_TO_DATE('$edate' , '%m/%d/%Y' ) )<=0";
$ApprovalResu = mysql_query($Approval,$link);


$filename="claim_file.xlsx";
//$filenametemp="cash2u_claim_file_".date("Ymd").".xlsx";
$subject = "Cash2u File for Collection Action_".date("Ymd");
//debug later for this message information
$message = "Hi ".$CollectonAgency.
	",\n\nPlease collect the payments from our customers listed in the attached file. 
	\nCash2u.ca appreciates your hardworking!
	\nCash2.ca Team\n";


/*header('Content-Description: File Transfer');
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
ob_clean();
    flush();
*/
/*
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($filename));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filename));
    ob_clean();
    flush();

readfile($filename);
*/

//header("Content-disposition: attachment; filename=".$filename);
//header("Content-type: application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//readfile($filename);


//debug later: here no download is required and will send the file to agency directly


			//move_uploaded_file($filename,"temp/" . $filenametemp);

			
			if (mail_attachment($filename,$collectionreport,$inmail,'cash2u',$inmail,$subject,$message)){
				echo "Email has been sent to destination.";

				//back up sent out email with attachment
				mail_attachment($filename,$inmail,$inmail,'cash2u',$inmail,'Backup Collection='.date("Ymd"),$message);


			}
			else {
				echo "Failed to send email.";
			}

}

//send attachment email function
function mail_attachment($filename, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
	$file = $filename;
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $uid = md5(uniqid(time()));
    $name = basename($file);
    $header = "From: ".$from_name." <".$from_mail.">\r\n";
    $header .= "Reply-To: ".$replyto."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $message."\r\n\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";
    if (mail($mailto, $subject, "", $header)) {
        return true;
    } else {
        return false;
    }
}



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cash2u.ca: Payday loan Application process</title>
<META NAME="Description" CONTENT=Cash2u.ca offers online payday loans and cash advance for Canadians">
<script type="text/javascript">
	window.open('', '_self', ''); var tid = window.setTimeout("window.close()", 3000);
	
	function toDownload(url){
		location = 'downloadFTP.php?target='+url;
	}
</script>
</head>
<body>
<div id="maincontainer">

        <form method="post" action="">
	<table>	
	<tr>
<?php if($FinalStatus == 1 && $FinalDecision==3) { ?>
	<td width="740" align="left">New application has been approved,</br></br>

A payday loan from applicant <?php echo $FirstName;?> has been approved. The scheduled repay day is <?php echo $_POST['A_payday'];?></br></br>

		</td> <?php } ?>

<?php if($FinalStatus == 1 && $FinalDecision==5) { ?>
	<td width="740" align="left">New application has been refused,</br></br>

A payday loan from applicant <?php echo $FirstName;?> has been refused due to <?php echo $_POST['A_reason'];?></br></br>

		</td> <?php } ?>

<?php if($FinalStatus == 1 && $FinalDecision==10) { ?>
	<td width="740" align="left">questions,</br></br>

More questions need to ask applicant <?php echo $FirstName;?> </br></br>

		</td> <?php } ?>

<?php if($FinalStatus == 3) { ?>
	<td width="740" align="left">Loan Repayment Process</br></br>

This is loan payment process</br></br>

		</td> <?php } ?>

<?php if($FinalStatus == 4) { ?>
	<td width="740" align="left">NSF Process</br></br>

This is NSF process</br></br>

		</td> <?php } ?>

<?php if($FinalStatus == 9) { ?>
	<td width="740" align="left">Agency Process</br></br>

This is to send Agency process</br></br>

		</td> 
<?php } ?>

<?php if($FinalStatus == 10) { ?>
	<td width="740" align="left">In Collection Agency</br></br>

The file has been sent to collection Agency</br></br>

		</td> <?php } ?>


<?php if($FinalStatus == 7) { ?>
<script>
window.clearTimeout(tid);
</script>
	<td width="740" align="left">ACH Process,</br></br>

Payment and deposit has been processed for this customer</br></br>

Please download files: <a href='#' onclick='toDownload("pad<?php echo date('Ymd').$morningafternoon;?>.txt")'>PAD</a>&nbsp&nbsp
<a href='#' onclick='toDownload("pds<?php echo date('Ymd').$morningafternoon;?>.txt")'>PDS</a>

		</td>
<?php } ?>

		</tr>

	</table>

	</form>
	
	
</div>
</body>
</html>
